package com.ruoyi.pms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.pms.domain.PmsGoods;
import com.ruoyi.pms.service.IPmsGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品列表Controller
 * 
 * @author yf
 * @date 2022-02-20
 */
@RestController
@RequestMapping("/goods")
public class PmsGoodsController extends BaseController
{
    @Autowired
    private IPmsGoodsService pmsGoodsService;

    /**
     * 查询商品列表列表
     */
    @RequiresPermissions("pms:goods:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsGoods pmsGoods)
    {
        startPage();
        List<PmsGoods> list = pmsGoodsService.selectPmsGoodsList(pmsGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品列表列表
     */
    @RequiresPermissions("pms:goods:export")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsGoods pmsGoods)
    {
        List<PmsGoods> list = pmsGoodsService.selectPmsGoodsList(pmsGoods);
        ExcelUtil<PmsGoods> util = new ExcelUtil<PmsGoods>(PmsGoods.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
    @RequiresPermissions("pms:goods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsGoodsService.selectPmsGoodsById(id));
    }

    /**
     * 新增商品列表
     */
    @RequiresPermissions("pms:goods:add")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsGoods pmsGoods)
    {
        return toAjax(pmsGoodsService.insertPmsGoods(pmsGoods));
    }

    /**
     * 修改商品列表
     */
    @RequiresPermissions("pms:goods:edit")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsGoods pmsGoods)
    {
        return toAjax(pmsGoodsService.updatePmsGoods(pmsGoods));
    }

    /**
     * 删除商品列表
     */
    @RequiresPermissions("pms:goods:remove")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsGoodsService.deletePmsGoodsByIds(ids));
    }
}
